package com.mxpio.erp.common.equipment.entity;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.mxpio.erp.common.jpa.model.Order;
import com.mxpioframework.filestorage.entity.MxpioFileInfo;
import com.mxpioframework.security.annotation.Dict;
import com.mxpioframework.security.entity.Dept;
import com.mxpioframework.security.entity.User;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
import javax.persistence.Transient;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

/**
 * 保养任务对象 MB_ERP_EQUIPMENT_UPKEEP_TASK
 * 
 * @author Cheng
 * @date 2023-07-28
 */
@Data
@EqualsAndHashCode(callSuper=false)
@Entity
@Table(name = "MB_ERP_EQUIPMENT_UPKEEP_TASK")
@Schema(description="保养任务")
public class EquipmentUpkeepTask extends Order {

private static final long serialVersionUID=1L;

    @Column(name = "TARGET_TYPE_")
    @Schema(description = "目标类型")
    @Dict(dicCode = "ERP_EQUIPMENT_TASK_TARGET_TYPE")//区域/设备
    private String targetType;

    @Column(name = "EXEC_STATUS_")
    @Schema(description = "执行状态")
    @Dict(dicCode = "ERP_EQUIPMENT_UPKEEP_TASK_EXEC")//执行中1、搁置2、等件3、委外4
    private String execStatus;

    @Column(name = "TARGET_ID_")
    @Schema(description = "目标ID")
    private String targetId;

    @Column(name = "TARGET_NAME_")
    @Schema(description = "目标名称")
    private String targetName;

    @Column(name = "TARGET_CODE_")
    @Schema(description = "目标编码")
    private String targetCode;

    @Column(name = "TARGET_SPEC_")
    @Schema(description = "设备型号")
    private String targetSpec;

    @Column(name = "CODE_ABC_")
    @Schema(description = "设备ABC码")//设备等级
    @Dict(dicCode="ERP_EQUIPMENT_EQP_CODE_ABC")
    private String codeAbc;

    @Column(name = "EQP_TYPE_ID_")
    @Schema(description = "设备分类ID")
    @Dict(dicCode="code", dicEntity = EquipmentCategory.class, dicText = "name")
    private String eqpTypeId;

    @Column(name = "EQP_TYPE_NAME_")
    @Schema(description = "设备分类")
    private String eqpTypeName;

    @Column(name = "USE_DEPT_ID_")
    @Schema(description = "使用单位")
    @Dict(dicCode = "deptCode", dicEntity = Dept.class, dicText = "deptName")
    private String useDeptId;
    //保养类型
    @Column(name = "UPKEEP_TYPE_")
    @Schema(description = "保养类型")//保养类型 深度2/计划1
    @Dict(dicCode="ERP_EQUIPMENT_UPKEEP_TYPE")
    private String upkeepType;

    @Column(name = "POSITION_")
    @Schema(description = "具体位置")
    private String position;

    @Column(name = "ORDER_STATUS_")
    @Schema(description = "工单状态")
    @Dict(dicCode = "ERP_EQUIPMENT_UPKEEPTASK_STATUS")
    private String orderStatus;

    @Column(name = "CREATE_TYPE_")
    @Schema(description = "生成类型")
    private String createType;

    @Column(name = "PLAN_START_TIME_")
    @Schema(description = "计划开始时间")
    @JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
    private Date planStartTime;

    @Column(name = "PLAN_END_TIME_")
    @Schema(description = "计划结束时间")
    @JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
    private Date planEndTime;

    /**工时定额（计划工时）*/
    @Schema(description = "工时定额（计划工时(h)）")//计划工时，后续计算计划结束时间使用
    @Column(name = "plan_HOUR_RATION_")
    private Integer planHourRation;

    /**实际工时（汇报工时）*/
    @Schema(description = "实际工时（汇报工时(h)）")//完工时页面填写
    @Column(name = "ACTUAL_HOUR_RATION_")
    private BigDecimal actualHourRation;

    @Column(name = "RELEASE_TARGET_TYPE_")
    @Schema(description = "下达目标类型")
    @Dict(dicCode = "ERP_EQUIPMENT_RELEASE_TARGET_TYPE")//部门、群组、个人
    private String releaseTargetType;

    @Column(name = "RELEASE_TARGET_ID_")
    @Schema(description = "下达目标")
    private String releaseTargetId;

    @Column(name = "RELEASE_TARGET_NAME_")
    @Schema(description = "下达目标")
    private String releaseTargetName;

    @Column(name = "IS_AUTO_RELEASE_")
    @Schema(description = "是否自动下达")
    @Dict(dicCode = "ERP_COMMON_YESNO")
    private Integer isAutoRelease;

    @Column(name = "DIRECTOR_")
    @Schema(description = "部门/群组责任人")
    private String director;

    @Column(name = "PLAN_RELEASE_TIME_")
    @Schema(description = "计划下达时间")
    @JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
    private Date planReleaseTime;

    @Column(name = "ADVANCE_TIME_")
    @Schema(description = "提前下达时间(天)")//按天
    private Integer advanceTime;

    @Column(name = "DISPATCH_MODE_")
    @Schema(description = "派工模式")
    @Dict(dicCode = "ERP_EQUIPMENT_DISPATCH_MODE")//抢单/派工
    private String dispatchMode;

    @Column(name = "ACTUAL_START_TIME_")
    @Schema(description = "实际开始时间")
    @JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
    private Date actualStartTime;

    @Column(name = "ACTUAL_END_TIME_")
    @Schema(description = "实际结束时间")
    @JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
    private Date actualEndTime;

    @Column(name = "IS_LAG_")
    @Schema(description = "滞后下达")
    @Dict(dicCode = "ERP_COMMON_YESNO")
    private Integer isLag;

    @Column(name = "LAG_TIME_")
    @Schema(description = "滞后下达时间")
    @JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
    private Date lagTime;

    @Column(name = "EXECUTOR_")
    @Schema(description = "执行人")
    @Dict(dicCode = "username", dicEntity = User.class, dicText = "nickname")
    private String executor;

    @Column(name = "EQP_STATUS_")
    @Schema(description = "设备开关机状态")
    @Dict(dicCode = "ERP_COMMON_YESNO")
    private String eqpStatus;

    @Column(name = "RELEASE_TIME_")
    @Schema(description = "下达时间")
    @JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
    private Date releaseTime;

    @Column(name = "DISPATCH_TIME_")
    @Schema(description = "派工时间")
    @JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
    private Date dispatchTime;

    @Column(name = "DISPATCH_USER_")
    @Schema(description = "派工操作人")
    @Dict(dicCode = "username", dicEntity = User.class, dicText = "nickname")
    private String dispatchUser;

    @Column(name = "OVER_FLAG_")
    @Schema(description = "是否逾期（0-正常；1-逾期）")
    @Dict(dicCode = "ERP_COMMON_YESNO")
    private Integer overFlag;

    @Column(name = "WORK_MINUTES_")
    @Schema(description = "保养工时(分钟)")
    private Long workMinutes;

    @Column(name = "VETO_REASON_")
    @Schema(description = "否决原因")
    private String vetoReason;

    @Column(name = "EVALUATE_DATE_")
    @Schema(description = "评价时间")
    private Date evaluateDate;

    @Dict(dicCode = "username", dicEntity = User.class, dicText = "nickname")
    @Schema(description = "评分人")
    @Column(name = "EVALUATE_USER_")
    private String evaluateUser;

    @Column(name = "PMIS_HOLD_")
    @Schema(description = "PMIS占用")
    @Dict(dicCode = "ERP_EQUIPMENT_UPKEEP_TASK_PMIS_HOLD")
    private String pmisHold;

    @Column(name = "UPKEEP_GROUP_CODE_")
    @Schema(description = "保养群组")
    @Dict(dicCode="groupCode", dicEntity = EquipmentPersonGroup.class, dicText = "groupName")
    private String upkeepPersonGroupCode;

    @Column(name = "ENGINEER_GROUP_CODE_")
    @Schema(description = "工程师组")
    @Dict(dicCode="groupCode", dicEntity = EquipmentPersonGroup.class, dicText = "groupName")
    private String engineerPersonGroupCode;

    @Schema(description = "提交附件")//提交环节附件
    @Column(name = "ATTACH_FILE_", columnDefinition = "text")
    @Dict(dicCode = "fileNo", dicEntity = MxpioFileInfo.class, dicText = "fileName")
    private String attachFile;

    @Dict(dicCode = "username", dicEntity = User.class, dicText = "nickname")
    @Schema(description = "验收人")
    @Column(name = "ACCEPTOR_")
    private String acceptor;

    @Transient
    private List<EquipmentUpkeepTaskDetail> upkeepTaskDetails;

    @Transient
    private String reason;

    @Transient
    @Schema(description = "验收原因")
    private String checkResult;

    @Column(name = "IS_USABLE_")
    @Schema(description = "是否保养成功")
    @Dict(dicCode = "MB_SYSTEM_YES_NO")
    private Integer isUsable;

    @Column(name = "PLAN_ID_")
    @Schema(description = "保养计划ID")
    private String planId;

    @Column(name = "PLAN_CODE_")
    @Schema(description = "保养计划编码")
    private String planCode;

    @Column(name = "PLAN_NAME_")
    @Schema(description = "保养计划名称")
    private String planName;

    @Column(name = "TASK_INDEX_")
    @Schema(description = "任务索引（计划生成的任务顺序号）")
    private Integer taskIndex;

    @Column(name = "NEXT_FLAG_")
    @Schema(description = "下一个待下达标识")
    @Dict(dicCode = "ERP_COMMON_YESNO")
    private String nextFlag;

    @Column(name = "IS_PUSH_")
    @Schema(description = "是否推送")
    @Dict(dicCode = "ERP_COMMON_YESNO") //0：不推送 1：推送
    private String isPush;

    @Column(name = "IS_EMAIL_")
    @Schema(description = "是否进行推送-邮件")
    @Dict(dicCode = "ERP_COMMON_YESNO") //0：否 1：是
    private String isEmail;

    @Override
    public String initTypeCode() {
        return "WMO1";
    }
}
